---
description: "Reference for Nitric's v0 Go library - Retrieves the value from a version of a secret."
---

# Go - Secret.Version.Access()

Retrieves the value from a version of a secret.

```go
import (
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  secret, err := nitric.NewSecret("secret-name").With(nitric.SecretAccessing)
  if err != nil {
    return
  }

  value, err := secret.Latest().Access(context.TODO())
  if err != nil {
    return
  }

  fmt.Println(value.AsString())

  nitric.Run()
}
```

## Parameters

<Properties>
  <Property name="ctx" required type="context">
    The context of the call, used for tracing.
  </Property>
</Properties>

## Examples

### Access the latest version of a secret

```go
import (
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  secret, err := nitric.NewSecret("secret-name").With(nitric.SecretAccessing)
  if err != nil {
    return
  }

  value, err := secret.Latest().Access(context.TODO())
  if err != nil {
    return
  }

  fmt.Println(value.AsString())

  nitric.Run()
}
```

### Access a specific version of a secret

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  secret, err := nitric.NewSecret("secret-name").With(nitric.SecretAccessing)
  if err != nil {
    return
  }

  version, err := secret.Version("the-version-id").Access(context.TODO())
  if err != nil {
    fmt.Println(err)
    return
  }

  fmt.Println(version.AsString())

  nitric.Run()
}
```
